package org.swxjava.assembler.avm1.convert;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;

import org.swxjava.assembler.Converter;
import org.swxjava.assembler.MarshallException;
import org.swxjava.assembler.ObjectCompiler;
import org.swxjava.assembler.avm1.AsDate;

public class DateConverter extends BaseConverter implements Converter {
	
	public ObjectCompiler convert(Object data) throws MarshallException {
		ObjectCompiler asDate = null;
		
		if (data instanceof Calendar) {
			asDate = new AsDate((Calendar)data);
			
		} else if (data instanceof Date || data instanceof java.sql.Date || data instanceof Timestamp) {
			asDate = new AsDate((Date) data);
			
		} else {
		    throw new MarshallException(data.getClass());
		    
		}
		return asDate;
	}
	
}
